package com.douxg.learning.spring;

import com.douxg.learning.spring.bean.BeanTwo;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.yaml.snakeyaml.Yaml;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.net.URL;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @Description
 * @Auther douxg
 * @Date 2021/4/22 9:50
 */
@Configuration
@ComponentScan("com.douxg.learning.spring")
//@PropertySource(value = "config.yml", factory = YAMLPropertySourceFactory.class)
@PropertySource(value = "config.properties")
public class Start {
    public static void main(String[] args) throws FileNotFoundException {
        ApplicationContext ctx = new AnnotationConfigApplicationContext(Start.class);
        Environment environment = ctx.getEnvironment();
        BeanTwo beanTwo = ctx.getBean("beanTwo", BeanTwo.class);
        beanTwo.getBeanOne().run();
        beanTwo.run();
        Yaml yaml = new Yaml();
        URL url = Start.class.getClassLoader().getResource("config.yml");
        File file = new File("config.yml");
        LinkedHashMap<String,Object> object = yaml.load(new FileReader(url.getFile()));
        System.out.println(beanTwo.getBeanOne().getA());
        System.out.println(beanTwo.getB());

    }
}
